package cn.dengta.webapp.user.vo;

import javax.annotation.Nullable;

import cn.dengta.common.model.Status;
import cn.dengta.common.web.Client;
import cn.dengta.context.model.WesKit;
import cn.dengta.webapp.base.entity.I18nContent;
import cn.dengta.webapp.base.vo.AbstractVO;
import cn.dengta.webapp.user.entity.AppInfo;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.X;

@Getter
@Setter
public class AppInfoVO extends AbstractVO<AppInfo> {

	/** 分包 */
	private WesKit wesKit;

	/** APP客户端类型：2=Android；3=iOS {@link cn.dengta.common.web.Client} */
	public String client;
	/** 版本号 */
	public String version;
	/** 版本号（整数标识） */
	public Integer versionInt;
	/** Logo */
	public String logo;
	/** 版本描述 */
	public Object desc;
	/** 渠道 */
	private String channel;
	/** 下载链接 */
	public String downloadUrl;
	/** 是否强制更新 */
	public transient Integer isMandatory;
	/** 启用状态 */
	public Integer status;

	public static AppInfoVO from(@Nullable AppInfo source) {
		AppInfoVO vo = copy(source, AppInfoVO::new);
		if (vo != null) {
			vo.desc = X.map(source.getResolvedLanguageCfg(), I18nContent::getDataMap);
		}
		return vo;
	}

	public static AppInfoVO fromFront(@Nullable AppInfo source) {
		AppInfoVO vo = copy(source, AppInfoVO::new);
		if (vo != null) {
			vo.desc = X.map(source.getResolvedLanguageCfg(), I18nContent::get);
		}
		return vo;
	}

	public Integer getMandatory() {
		return isMandatory;
	}

	public boolean getCanOn() {
		return Status.NO.eq(status);
	}

	public String getStatus_() {
		if (status != null) {
			switch (status) {
				case -1:
					return "审核通过";
				case 0:
					return "待审核";
				case 1:
					return "已发布";
			}
		}
		return null;
	}

	public String getIsMandatory_() {
		return X.map(Status.of(isMandatory), Status::getLabel);
	}

	public String getClient_() {
		return X.map(Client.of(client), Client::getLabel);
	}

	public String getWesKit_() {
		return this.wesKit != null ? this.wesKit.getLabel() : null;
	}

	public Integer getWesKit() {
		return wesKit == null ? null : wesKit.value;
	}

}
